package com.example.service.webhook.business.carrier.service;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.example.service.webhook.business.carrier.entity.MobileVoiceCallEntity;
import com.example.service.webhook.business.carrier.repository.MobileVoiceCallRepository;
import com.example.service.webhook.business.carrier.repository.MobileVoiceRepairRepository;

@Service
public class RepairService {
	private static final Logger LOGGER = LoggerFactory.getLogger(RepairService.class);

	
	
	@Autowired
	private MobileVoiceCallRepository mobileVoiceCallRepository;
	@Autowired
	private MobileVoiceRepairRepository mobileVoiceRepairRepository;
	
	public void repairVoiceCall(){
		
		int minid=0;
		int maxid = mobileVoiceRepairRepository.countMobileVoice();
		
		if(maxid>0){
			
			while(minid<maxid){
				 List<MobileVoiceCallEntity> list = mobileVoiceRepairRepository.queryList(minid, minid+=1000);
				if(list!=null&&list.size()>0){
					for(MobileVoiceCallEntity mobileVoiceCallEntity:list){
						mobileVoiceCallEntity.setId(0);
						try {
							mobileVoiceCallRepository.saveMobileVoiceCall(mobileVoiceCallEntity);
						} catch (Exception e) {
							LOGGER.error("repairVoiceCall error"+e.getMessage(),e);
						}
					}
					
				}
				
			}
			
		}
		
	}
      
	
}
